package com.tan.listen;

import com.tan.util.SendEmailUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @description:
 * @author: longshifu
 * @time: 2022/8/3 21:16
 */
@Component
@RabbitListener(queues = "blog.queue")
public class BlogReceiver {
    @Autowired
    SendEmailUtil sendEmailUtil;

    @RabbitHandler
    public void addBlogReceiver(Map map) {
        System.out.println("接收的消息是：" + map.toString());
        String operate = (String) map.get("operate");
        String blogTitle = map.get("blogTitle").toString();
        String text = "新增了一篇文章：" + blogTitle;
        if ("修改".equals(operate)) {
            text = "文章: " + blogTitle + " 已修改";
        }
        sendEmailUtil.sendMail(operate,text , "857267635@qq.com");
    }

}
